package org.redis.cluster.transport.netty.client;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class NettyClientHandler extends SimpleChannelInboundHandler<byte[]> {
	
	private final BlockingQueue<byte[]> response=new ArrayBlockingQueue<>(1);
	
	@Override
	protected void channelRead0(ChannelHandlerContext ctx, byte[] msg) throws Exception {
		this.response.offer(msg);
	}
	
	public byte[] getResponse(long timeout,TimeUnit unit) throws InterruptedException {
		return response.poll(timeout, unit);
	}

}